// src/main/java/com/example/ruleengine/engine/RuleEngineRunner.java
package com.example.ruleenginelearning.easyrule.engine;
import com.example.ruleenginelearning.easyrule.rules.NewOrderRule;
import com.example.ruleenginelearning.easyrule.rules.ProcessingOrderRule;
import com.example.ruleenginelearning.example.model.Order;

import com.example.ruleenginelearning.easyrule.rules.ShippedOrderRule;
import org.jeasy.rules.api.*;
import org.jeasy.rules.core.*;

public class RuleEngineRunner {
    public static void main(String[] args) {
        // 1. 创建规则引擎
        RulesEngineParameters params = new RulesEngineParameters()
            .skipOnFirstAppliedRule(true); // 匹配即停止
        RulesEngine engine = new DefaultRulesEngine(params);

        // 2. 注册规则
        Rules rules = new Rules(
            new NewOrderRule(),
            new ProcessingOrderRule(),
            new ShippedOrderRule()
        );

        // 3. 准备事实数据
        Order order = new Order("ORD-2023", "NEW");
        order.setAmount(1000);
        order.setVip(true);
        Facts facts = new Facts();
        facts.put("order", order);

        // 4. 执行规则
        System.out.println("【规则执行前】状态: " + order.getStatus());
        engine.fire(rules, facts);
        System.out.println("【规则执行后】状态: " + order.getStatus());
    }
}